﻿using OpenCvSharpExtension;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF.DEMO
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            (menu.Children[menu.Children.Count - 1] as RadioButton).IsChecked = true;

            //var decoder = System.Windows.Media.Imaging.BitmapDecoder.Create(new Uri(@"C:\Users\sharp\Pictures\未标题-2.png"), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            //var frame = decoder.Frames[0];
            //var bs = SharpSoft.WPF.BitmapHelper.ToByteArray(frame);
            //var s = $"{bs.Length / (1024d * 1024):0.00}";
            //WriteableBitmap bmp = new WriteableBitmap(frame.PixelWidth, frame.PixelHeight, frame.DpiX, frame.DpiY, frame.Format, frame.Palette);
            //SharpSoft.WPF.BitmapHelper.Blit(bmp, bs);
            //// img.Source = bmp;

            //SharpSoft.WPF.Controls.SequenceImage.GenerateSequenceImageFile(@"C:\Users\sharp\Documents\Tencent Files\534994635\FileRecv\邮政动画\邮政男", @"res\a.bin", 24, 0);

            //var fs = new FileStream(@"res\a.bin", FileMode.Open, FileAccess.Read);
            //var info = SharpSoft.WPF.Controls.SequenceImage.OpenSequenceImageFile(fs);
            //var pf = info.GetPixelFormat();

            this.Background = new ImageBrush(BitmapHelper.LoadImageByOpenCV(@"res\webpTest.webp"));
        }

        private void StackPanel_Checked(object sender, RoutedEventArgs e)
        {
            if (e.Source is RadioButton rb && rb.Tag is Type t)
            {
                var obj = Activator.CreateInstance(t);
                if (obj is Page p)
                {
                    frame.Navigate(p);
                }
            }
        }

        private void frame_Navigated(object sender, NavigationEventArgs e)
        {

        }

        private void frame_Navigating(object sender, NavigatingCancelEventArgs e)
        {
            tec.SnapshotAndStart();
        }
    }
}
